<?php

namespace app\shop\controller;

use think\Controller;

class Product extends Controller
{
  // 控制器初始化
  public function _initialize()
  {
    parent::_initialize();
    // 实例化模型   
    $this->BusinessModel = model('Business.Business');
    $this->ProductModel = model('Product.Product');
    $this->ProductTypeModel = model('Product.Type');
    $this->OrderProductModel = model('Product.OrderProduct');
  }

  // 分类图片
  public function type()
  {
    $id = $this->request->param('id', 0, 'trim');

    $info = $this->ProductTypeModel->find($id);

    if (!$info) {
      return json(['code' => 0, 'msg' => '分类图片不存在', 'data' => '']);
    }

    return json(['code' => 1, 'msg' => '', 'data' => $info['thumb_text']]);
  }


  // 单张图片
  public function thumbstext()
  {
    $id = $this->request->param('id', 0, 'trim');

    $info = $this->ProductModel->find($id);

    if (!$info) {
      return json(['code' => 0, 'msg' => '产品图片不存在', 'data' => '']);
    }

    return json(['code' => 1, 'msg' => '', 'data' => $info['thumbs_text']]);
  }

  // 多张图片
  public function thumbslist()
  {
    $id = $this->request->param('id', 0, 'trim');

    $info = $this->ProductModel->find($id);

    if (!$info) {
      return json(['code' => 0, 'msg' => '产品图片不存在', 'data' => '']);
    }

    return json(['code' => 1, 'msg' => '', 'data' => $info['thumbs_list']]);
  }

  // 评价图片
  public function rate()
  {

    $orderproid = $this->request->param('orderproid', 0, 'trim');

    $info = $this->OrderProductModel->find($orderproid);

    if (!$info) {
      return json(['code' => 0, 'msg' => '订单商品不存在', 'data' => '']);
    }

    $res = upload($orderproid);

    if ($res['code'] == 0) {
      return json(['code' => 0, 'msg' => $res['msg']]);
    }

    return json(['code' => 1, 'msg' => '上传成功', 'data' => $res['data']]);
  }

  //商品图片？
  public function proimglist()
  {
    $id = $this->request->param('id', 0, 'trim');

    $info = $this->OrderProductModel->find($id);

    if (!$info) {
      return json(['code' => 0, 'msg' => '图片不存在', 'data' => '']);
    }

    return json(['code' => 1, 'msg' => '', 'data' => $info['proimg_list']]);
  }


  
}
